﻿Imports System.ComponentModel

Namespace Core.Controls
    Public Class AlbumPreview

        Public Shared ReadOnly BackBrushProperty As DependencyProperty =
            DependencyProperty.Register("BackBrush", GetType(Brush), GetType(AlbumPreview))

        Public Shared Shadows ReadOnly BorderBrushProperty As DependencyProperty =
            DependencyProperty.Register("BorderBrush", GetType(Brush), GetType(AlbumPreview))

        Private __AlbumBase As String

        Public Sub New()

            ' This call is required by the designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.

            Me.DataContext = Me

        End Sub

        Private Sub DoRender(ByVal sender As Object, ByVal e As EventArgs) Handles Me.PropertyChanged
            Console.WriteLine("Stardust>Yeah!")
        End Sub

        Public Sub FillPreview(ByVal Images As List(Of Uri))
            If ((Images.Count > 0) And (Images IsNot Nothing)) Then
                Try
                    Dispatcher.BeginInvoke(Sub()
                                               If (Images(0)) IsNot Nothing Then
                                                   Me.Image1 =
                                                   Stardust.Core.Render.LoadThumbnail(
                                                       Images(0)
                                                           )
                                               End If
                                           End Sub, Windows.Threading.DispatcherPriority.Background
                                           )

                    Dispatcher.BeginInvoke(Sub()
                                               If (Images(1)) IsNot Nothing Then
                                                   Me.Image2 =
                                                   Stardust.Core.Render.LoadThumbnail(
                                                       Images(0)
                                                           )
                                               End If
                                           End Sub, Windows.Threading.DispatcherPriority.Background
                                           )

                    Dispatcher.BeginInvoke(Sub()
                                               If (Images(2)) IsNot Nothing Then
                                                   Me.Image3 =
                                                   Stardust.Core.Render.LoadThumbnail(
                                                       Images(2)
                                                           )
                                               End If
                                           End Sub, Windows.Threading.DispatcherPriority.Background
                                           )
                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
            End If
        End Sub

        Public Overrides Function ToString() As String
            Return __AlbumBase
        End Function

        Public Property AlbumTitle As String
            Get
                Return TextBlock1.Text
            End Get
            Set(ByVal value As String)
                TextBlock1.Text = value
            End Set
        End Property

        Public Property AlbumBase As String
            Get
                Return __AlbumBase
            End Get
            Set(ByVal value As String)
                __AlbumBase = value
            End Set
        End Property

        Public Overloads Property Foreground As Brush
            Get
                Return TextBlock1.Foreground
            End Get
            Set(ByVal value As Brush)
                TextBlock1.Foreground = value
            End Set
        End Property

        Public Property BackBrush As Brush
            Get
                Return GetValue(BackBrushProperty)
            End Get
            Set(ByVal value As Brush)
                SetValue(BackBrushProperty, value)
            End Set
        End Property

        Public Shadows Property BorderBrush As Brush
            Get
                Return GetValue(BorderBrushProperty)
            End Get
            Set(ByVal value As Brush)
                SetValue(BorderBrushProperty, value)
            End Set
        End Property

#Region "Images"
        Public Property Image1 As ImageSource
            Get
                Return __Image1.Source
            End Get
            Set(ByVal value As ImageSource)
                __Image1.Source = value
            End Set
        End Property

        Public Property Image2 As ImageSource
            Get
                Return __Image2.Source
            End Get
            Set(ByVal value As ImageSource)
                __Image2.Source = value
            End Set
        End Property

        Public Property Image3 As ImageSource
            Get
                Return __Image3.Source

            End Get
            Set(ByVal value As ImageSource)
                __Image3.Source = value
            End Set
        End Property

#End Region

#Region "Events"
        Public Custom Event PropertyChanged As PropertyChangedEventHandler
            AddHandler(ByVal value As PropertyChangedEventHandler)
                Console.WriteLine("Stardust>WPF is listening my property changes so I must be visible")
            End AddHandler
            RemoveHandler(ByVal value As PropertyChangedEventHandler)
                Console.WriteLine("Stardust>WPF unsubscribed so I must be out of sight")
            End RemoveHandler
            RaiseEvent(ByVal Sender As Object, ByVal e As EventArgs)

            End RaiseEvent
        End Event

#End Region
    End Class


End Namespace
